$(bodyDimensions = function(){
	var dim;
	if(self.innerWidth!=undefined) {
		dim = [self.innerWidth,self.innerHeight];
	}
	else{
		var D= document.documentElement;
		if(D) {dim = [D.clientWidth,D.clientHeight];}
	}
	return dim;
});
/*$(function() {
	var b = bodyDimensions();
	log.debug(b[1])
});*/


function elementDimensions(elem){
	a = $(elem);
	offset = a.offset();
	return a = [offset.left , offset.top];
};


/* Присутствие
*******************************************/
$(function() {
	var which = $(".mP div");
	which.hover(
		function () { $(this).css('cursor','pointer'); },
		function () {}
	);
	which.click(function(){
		var obj = $(this);
		var cid = obj.attr('id');
		var oldClass = obj.attr('class')
		var oldText = obj.text();
		log.debug('oldClass = '+oldClass); log.debug('cid = '+cid);
		if(boxerInplace.inited == true) {
			boxerInplace.hide();
			obj.removeAttr('class').addClass(oldClass);
		} else {
			var text = '<div class="owBlock" style=""><ol style="list-style: none;">'
				+ '<li class="mpl1" title="mpOut"><a href=""  class="mpOut" title="неявка">неявка</a></li>'
				+ '<li class="mpl2" title="mpDelay"><a href="#" class="mpDelay" title="опоздание">опоздание</a></li>'
				+ '<li class="mpl3" title="mpIll"><a href="" class="mpIll" title="болезнь">болезнь</a></li>'
				+ '<li class="mpl4" title="mpPass"><a href="" class="mpPass" title="пропуск">пропуск</a></li>'
				+ '<li class="mpl5" title="mpNone"><a href="" class="mpNone" title="">отмена</a></li>'
				+ '</div>';
//			overlay = $('<div id="overlay"></div>').appendTo($("body")); // addon
			boxerInplace.show(obj , text , {delay : false ,className : "confirm2", xId:'boxerInplace2'});
			
			var linkObj = $('.owBlock li a');
			linkObj.hover(function(){
				var xClass = $(this).parent().attr('title');
				var xText = $(this).attr('title');
				obj.removeAttr('class').addClass(xClass);
				obj.children().empty().html(xText)
				$(this).click(function(){
					obj.removeAttr('class').addClass(xClass);
					boxerInplace.hide();
//					overlay.remove();
					return false;
				})
				/*overlay.click(function () {
					obj.removeAttr('class').addClass(oldClass);
					boxerInplace.hide();
					overlay.remove();
				});*/
			},
			function(){
				obj.removeAttr('class').addClass(oldClass);
//				obj.removeAttr('class').addAttr('class' , oldClass);
				obj.children().html(oldText);
			});
			
//			linkObj.click(function(){return false;});
		}
	});
});


/* Коментарии
 ********************************************/
$(function() {
	var which = $(".mC div span");

	which.click(function(){
		if (myComment.active != true) {
			var zArea = myComment.show($(this));
		}
		zArea.blur(function(){
//			$('.owButSubmit').click(function(){myComment.hideOk();});
			myComment.hide();
		});
		zArea.keypress(function (e) {
			if (e.which == 13){ myComment.hide(); }
		});

	});
	var destr = $(".mC div a");
	destr.click(function(){
		/*boxerInplaceConfirm(
				this, 
				"Подтверждаете удаление?", 
				function () {
					myComment.destroy($(this));
				});*/
			myComment.destroy($(this));
			return false;
	});
});


/*
 * все функции стартуют от контролов событий прописанных отдельно (выше)
 */
(function($){
myComment = {
	options : {
		buttons : []
		,zActive : false
		,zTextDefault : 'нажмите что бы добавить коментарий'
	},
	
	show: function (element) {
		var zThis = element;
		this.zElement = element;
		this.zTextOld = zThis.html();
		this.zOldType = zThis.parent().attr('class');
		this.zElement.parent().removeClass(this.zOldType);

		var zAreaText = '';
		if (this.zOldType == 'mcText') {zAreaText = this.zTextOld;}
		var zHtml = '<div class="zDiv" style="z-index:1000;"><textarea style="font-size:11px; width:210px; height:100px;" class="zText">'
				+ zAreaText + '</textarea>'
				+'</div>';
		
		if (this.active != true) {
//		$('<div style="position:absolute; top:0; left:0; width:100%; height:100%; z-index:100;" id="overlay"></div>').appendTo($("body"));
			zThis.empty().html(zHtml);
			this.zElement.parent().find('a').hide();
			var zArea = zThis.find('textarea');
			zArea.focus();
		
			this.active = true;
			return zArea;
		}
	},
	/*
	 * "прячет" textarea сохраняя результат
	 */
	hide: function() {
		this.zNewText = $('.zDiv textarea').val();
		if(this.zNewText == '') {
			//myAjax.response();
			this.zElement.parent().addClass('mcNone');
			zHtmlOut = this.options.zTextDefault;
			this.zElement.parent().find('a').hide();
		}
		else {
			zHtmlOut = ''+ this.zNewText +'';
			this.zElement.parent().addClass('mcText');
			this.zElement.parent().find('a').show();
		}
		this.zElement.empty().html(zHtmlOut);
		
		this.active = false;
	},
	/*
	 * удаляет текст комментария и сбрасывает на дефолты
	 */
	destroy : function(element) {
		element.parent().removeClass().addClass('mcNone');
		zHtmlOut = this.options.zTextDefault;
		element.parent().find('span').empty().html(zHtmlOut);
		element.hide();
	}
};
})(jQuery);




/* Marks
*******************************************/
$(function() {
	var arrMarks = ['1-', '1', '1+', '2-', '2', '2+', '3-', '3', '3+', '4-', '4', '4+', '5-', '5', '5+'];
//	$('.test1').html(arrMarks[8]);
	
	var which = $('li.mmPlace');
	
	which.hover(
		function () { $(this).addClass('mmHover');},
		function () { $(this).removeClass('mmHover'); }
	);
	
	which.click(function() {
		var obj = $(this);
		var cid = obj.attr('id');
		var oldClass = obj.attr('class')
		var oldMark = obj.text();

		if(boxerInplace.inited == true) {
			boxerInplace.hide();
			obj.removeAttr('class').addClass(oldClass);
		} else {
			var text = 
				'<div class="mmBigMark"><div class="mmbMarkMinus">-</div><div class="mmbMarkPlace">*</div><div class="mmbMarkPlus">+</div></div>'
				+'<ol style="list-style: none;">'
					+ '<li class="mml1" title="mmOne"><a href="" class="mm1" title="1">1</a></li>'
					+ '<li class="mml2" title="mmTwo"><a href="#" class="mm2" title="2">2</a></li>'
					+ '<li class="mml3" title="mmThree"><a href="" class="mpIll" title="3">3</a></li>'
					+ '<li class="mml4" title="mmFor"><a href="" class="mpPass" title="4">4</a></li>'
					+ '<li class="mml5" title="mmFive"><a href="" class="mpNone" title="5">5</a></li>'
				+ '</ol><div class="mmDelet"><a href="">удалить</a></div>'
				+ '</div>';
//			overlay = $('<div id="overlay"></div>').appendTo($("body")); // addon
			boxerInplace.show(obj , text , {delay : false ,className : "confirm2", xId:'boxerInplace4'});
			
			var linkObj2 = $('.text li');
			linkObj2.hover(
			function(){
				var xMarkObj = $(this).find('a');
				xfxf = xMarkObj.html();
//				alert(xfxf);
				xzz = obj.find('.mmbMarkPlace');
//				alert(xcxc);
				xzz.text(xfxf);
			},
			function () {

			}
			);
			
			var linkObj = $('.owBlock li a');
			linkObj.hover(function(){
				var xClass = $(this).parent().attr('title');
				var xText = $(this).attr('title');
				var xWindMarkVal = $(this).text();
				
				//obj.removeAttr('class').addClass(xClass);
				//obj.children().empty().html(xText)
				
				obj.text(xWindMarkVal);
				$(this).click(function(){
					//obj.removeAttr('class').addClass(xClass);
					obj.text(xWindMarkVal);
					boxerInplace.hide();
//					overlay.remove();
					return false;
				})
				/*overlay.click(function () {
					obj.removeAttr('class').addClass(oldClass);
					boxerInplace.hide();
					overlay.remove();
				});*/
			},
			function(){
				//obj.removeAttr('class').addClass(oldClass);
				obj.children().html(oldText);
				obj.text(oldMark);
			});
			$('div .mmDelet').click(function() {
				obj.html('<span>x</span>');
				boxerInplace.hide();
				return false;
			});
		}
	});
});
	






/* AJAX
***********************************/
(function($){ myAjax = {
	option : {
		simpleAjax : false
	},
	response : function() {
		$('.test1').fadeOut(1000, function(){alert('OK');});
	}
};
})(jQuery);

/*$(function(){
	$('.test1').addClass('ffff');
});*/

/*$(function(){
	$('.mH').click(function(){
		boxerInplace.hide();
	});
});*/

/*$(function() {
	var d = $(".mPresence")
	boxerInplace.show(d , 'dsds' , {delay : false});
});*/




/*
log.debug( 'this is a debug message' );
log.info( 'this is an info message' );
log.warn( 'this is a warning message' );
log.error( 'this is an error message' );
*/

